package com.jinxin.platform.cdfaceacs.controller;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdfaceacs.bean.CdfaceacsAuthTempalte;
import com.jinxin.platform.cdfaceacs.bean.CdfaceacsDevice;
import com.jinxin.platform.cdfaceacs.bean.CdfaceacsWorker;
import com.jinxin.platform.cdfaceacs.rpc.SysUserRpc;
import com.jinxin.platform.cdfaceacs.service.IFaceAcsAuthTemplateService;
import com.jinxin.platform.cdfaceacs.service.IFaceAcsDeviceService;
import com.jinxin.platform.cdfaceacs.service.IFaceAcsWorkerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-05-21
 * @Author: Lingnan
 **/
@RestController
@RequestMapping("/faceAcsWorker")
@Slf4j
public class FaceAcsWorkerController {
    @Autowired
    private IFaceAcsWorkerService workerService;
    @Autowired
    private SysUserRpc sysUserRpc;
    @Autowired
    private IFaceAcsDeviceService acsDeviceService;
    @Autowired
    private IFaceAcsAuthTemplateService acsAuthTemplateService;

    @RequestMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,
                                   @RequestParam(required = false) String teamId,@RequestParam(required = false) String workTypeId,
                                   @RequestParam(required = false) String name){
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("searchKey", name);
        param.put("teamId", teamId);
        param.put("workTypeId", workTypeId);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","");
        resultMap.put("count", workerService.listPageCount(param));
        resultMap.put("data", workerService.listPage(param));
        return resultMap;
    }

    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdfaceacsWorker worker){
        return workerService.saveOrUpdate(worker);
    }

    @RequestMapping("/deleteAll")
    public JsonResult deleteAll(String params){
        return workerService.deleteAll(params);
    }

    @RequestMapping("/delete")
    public JsonResult delete(String id){
        return workerService.delete(id);
    }

    @RequestMapping("/batchAuth")
    public JsonResult batchAuth(String authTemplateId,String authTemplate,String params,String issueDevices){
        return workerService.batchAuth(authTemplateId,authTemplate,params,issueDevices);
    }

    @RequestMapping("/cancelBatchAuth")
    public JsonResult cancelBatchAuth(String params){
        return workerService.cancelBatchAuth(params);
    }

    @GetMapping("/getDictItems")
    public JsonResult getDictItems(String dictType){
        if(StringUtils.isEmpty(dictType)){
            return null;
        }
        return sysUserRpc.getDictItems(dictType);
    }

    @GetMapping("/listOptions")
    public JsonResult listDeviceAndTemplates(){
        HashMap param = new HashMap();
        List<CdfaceacsDevice> deviceList = acsDeviceService.list(param);
        List<CdfaceacsAuthTempalte> authTempalteList = acsAuthTemplateService.list(param);
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("deviceList",deviceList);
        resultMap.put("authTempalteList",authTempalteList);
        return JsonResult.ok(resultMap);
    }

}
